package com.bwie.controller;

import com.bwie.service.TbMenuService;
import com.bwie.service.TbUserService;
import com.bwie.utils.R;
import com.bwie.vo.UserLoginVo;
import com.bwie.vo.UserPageInfoVo;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/user/index")
@Slf4j
public class IndexController {

    @Autowired
    TbUserService userService;

    @Autowired
    TbMenuService menuService;

   @ApiOperation("用户分页")
   @PostMapping("/UserPageInfo/{pageNum}/{pageSize}")
   public R UserPageInfo(@PathVariable(name = "pageNum") Integer pageNum, @PathVariable(name = "pageSize")Integer pageSize, @RequestBody @Validated UserPageInfoVo userPageInfoVo){

       log.info("pageNum="+pageNum);
       log.info("pageSize="+pageSize);
       log.info("userPageInfoVo",userPageInfoVo);

       return userService.userList(userPageInfoVo);
   }


   @ApiOperation("发送验证码")
   @PostMapping("/sendCode")
   public R sendCode(@RequestBody UserLoginVo userLoginVo){
       return userService.sendCode(userLoginVo);
   }

   @ApiOperation("注册")
   @PostMapping("/regire")
   public R regire(@RequestBody UserLoginVo userLoginVo){
       return userService.regire(userLoginVo);
   }

   @ApiOperation("登录")
   @PostMapping("/userLogin")
   public R userLogin(@RequestBody UserLoginVo userLoginVo){
       return userService.userLogin(userLoginVo);
   }

    @ApiOperation("获取权限菜单")
    @PostMapping("/getMenuList")
    public R getMenuList(HttpServletRequest request){
        return  menuService.getMenuList(request);
    }
}
